package kbs.scm
{
    public class Env
    {
        public function Env(p:Env, e:Eval)
        {
            m_p = p;
            m_vars = {};
            m_evaluator = e;
        }

        public function getEvaluator():Eval
        { return m_evaluator; }
        public function lookup(v:String):Base
        {
            // Eval.scmdebug("Lookup "+v);
            var ret:Base = m_vars[v];
            // Alert.show("Found: "+ret);
            if (ret === null) {
                if (m_p === null) {
                    throw new Error("Unbound variable -- "+v);
                }
                return m_p.lookup(v);
            }
            else {
                return ret;
            }
        }

        public function store(n:String, v:Base):void
        {
            // Eval.scmdebug("Store "+n+" in `"+this+"'");
            m_vars[n] = v;
        }

        private var m_p:Env;
        private var m_vars:Object;
        private var m_evaluator:Eval;
    }
}
